#include <napi_call.h>
#include <node_api.h>

struct PropData {
    napi_value val = nullptr;
    const char *utf8name = "unknown";
};
PropData props[] = {
    {.utf8name = "array"},
    {.utf8name = "array_with_length"},
    {.utf8name = "arraybuffer"},
    // {.utf8name = "buffer"},
    // {.utf8name = "buffer_copy"},
    {.utf8name = "date"},
    // {.utf8name = "external"},
    // {.utf8name = "external_arraybuffer"},
    // {.utf8name = "external_buffer"},
    {.utf8name = "object"},
    // {.utf8name = "symbol"},
    // {.utf8name = "typedarray"},
    // {.utf8name = "dataview"},
    {.utf8name = "global"},
    {.utf8name = "null"},
    {.utf8name = "undefined"},
};

/* napi_value */
NAPI_MODULE_INIT(/* napi_env env, napi_value exports */)
{
    int index = 0;

    NAPI_CALL(env, napi_create_array(env, &props[index++].val)); // 0: object
    NAPI_CALL(env, napi_create_array_with_length(env, 3, &props[index++].val)); // 1: object ,,

    void *arraybuffer;
    NAPI_CALL(env, napi_create_arraybuffer(env, 8, &arraybuffer, &props[index++].val)); // 2: object [object ArrayBuffer]
    *reinterpret_cast<uint64_t *>(arraybuffer) = 0x3132333435363738;

    NAPI_CALL(env, napi_create_date(env, 0, &props[index++].val)); // 3: object Thu Jan 01 1970 08:00:00 GMT+0800 (中国标准时间)
    NAPI_CALL(env, napi_create_object(env, &props[index++].val)); // 4: object [object Object]
    NAPI_CALL(env, napi_get_global(env, &props[index++].val)); // 5. object global...
    NAPI_CALL(env, napi_get_null(env, &props[index++].val)); // 6. object null
    NAPI_CALL(env, napi_get_undefined(env, &props[index++].val)); // 7. undefined undefined

    for (auto &prop : props) {
        NAPI_CALL(env, napi_set_named_property(env, exports, prop.utf8name, prop.val));
    }
    return exports;
}
